The newly released Liberty BASIC v4.01 comes with WYSIWYG (What You See Is What You Get) capability. By using a graphics window (or graphicbox), the programmer has complete control over font color, style, and size. Printform.bas has been included with LB 4.01 to illustrate the new commands for printing the graphics window. The three new print commands are
#Handle, "Print VGA" 'Paper width simulates 640 pixels wide #Handle, "Print SVGA" 'Paper width simulates 800 pixels wide #Handle, "Print XGA" 'Paper width simulates 1024 pixels wide
If a graphicbox is opened in one of the three display sizes, the programmer can be assured the graphics will be printed in the relative size. In the demo below, varying font sizes can be chosen to view the effect in any of the three display sizes.
Note that using any of the following combinations:
Font size 22 with VGA ( 640 pixels wide)
Font size 28 with SVGA ( 800 pixels wide)
Font size 36 with XGA ( 1024 pixels wide)
will fill the width of the respective graphic windows. Thus, despite the differences in window sizes, the printout on paper is virtually identical to the screen display.
'Demonstrates Liberty the printing capability of Liberty BASIC v4.01
'to adjust the printed output relative to the selected display
'Displays are VGA, SVGA and XVGA
'Allows programmer to print to a graphics window for a WYSIWYG look
'Requires Liberty BASIC v4.x due to handle variable command
'and graphicbox print commands (e.g. #Handle, "Print SVGA"). The
'program will run in Liberty BASIC v4.0, but the printed results will
'be much smaller than WYSIWYG. Best printout with LB v4.1
'========================================
' GUI Controls
'========================================
Menu #w, "&Font Size","Change &Font Size",_
[fontSize],|,"E&xit",[yesExit]
Button #w.b1, "Open 640 x 480 Window ( VGA )", [640x480], UL, 60, 20
Button #w.b2, "Open 800 x 600 Window ( SVGA )", [800x600], UL, 60, 60
Button #w.b3, "Open 1024 x 768 Window ( XGA ) ", [1024x768], UL, 60, 100
win1Width = 400
win1Height = 300
WindowWidth = win1Width
WindowHeight = win1Height
UpperLeftX = Int((DisplayWidth-WindowWidth)/2)
UpperLeftY = Int((DisplayHeight-WindowHeight)/2)
Nomainwin
Graphicbox #w.g, -1, 150, 394, 97
chosenSize = 0
win2Width = 0
Open "Print Demo" for Window as #w
#w, "Trapclose [endProgram]"
fontSize = 10
Dim demoText$(6)
For i = 1 to 6
Read demoText$
demoText$(i) = demoText$
Next i
'========================================
' All Events Return Here
'========================================
[awaitUserInput]
#w.g, "Cls"
#w.g, "Font Courier_New ";fontSize
Call displayText "#w.g", fontSize
Wait
'========================================
' Program Ends Here
'========================================
[endProgram]
PopupMenu "&E&xit",[yesExit],|, _
"&Cancel",[noExit]
[noExit]
Wait
[yesExit]
Close #w
End
'========================================
' The Data Statements
'========================================
Data "Join the Liberty BASIC Community at"
Data "http://libertybasic.conforums.com. "
Data "Whatever your level of programming, "
Data "you'll find tips and techniques to "
Data "learn and share in the company of "
Data "friendly, encouraging experts."
'========================================
' Changing the Font Size
'========================================
[fontSize]
msg$ = "Current Font Size = ";fontSize;Chr$(13)
msg$ = msg$;Chr$(13);"New Font Size ";Chr$(13)
Prompt msg$;fontSize$
fontSize = Max(2,Val(fontSize$))
Goto [awaitUserInput]
'========================================
' The Screen Displays
'========================================
[640x480]
If win2Width = 0 Then
win2Width = 640
win2Height = 480
win2Title$ = "Screen Display VGA (640 pixels wide)"
screenSize$ = "Print VGA"
End If
[800x600]
If win2Width = 0 Then
win2Width = 800
win2Height = 600
win2Title$ = "Screen Display SVGA (800 pixels wide)"
screenSize$ = "Print SVGA"
End If
[1024x768]
If win2Width = 0 Then
win2Width = 1024
win2Height = 768
win2Title$ = "Screen Display XVGA (1024 pixels wide)"
screenSize$ = "Print XGA"
End If
WindowWidth = win2Width
WindowHeight = win2Height
UpperLeftX = Int((DisplayWidth-WindowWidth)/2)
UpperLeftY = Int((DisplayHeight-WindowHeight)/2)
If gWin = 1 Then
Close #g
End If
win2Title$ = win2Title$;" - Font Size: ";fontSize
Open win2Title$ for Graphics_nsb as #g
gWin = 1
#g, "Trapclose [closeG]"
#g, "Down"
#g, "Fill White"
#g, "Font Courier_New ";fontSize
Call displayText "#g", fontSize
msg$ = Word$(screenSize$, 2);Chr$(13)
msg$ = msg$;"Print to paper?"
Confirm msg$;yn$
If yn$ = "yes" Then
Print #g, screenSize$
End If
[closeG]
Close #g
gWin = 0
win2Width = 0
Goto [awaitUserInput]
'========================================
' Display the Demo Text
'========================================
Sub displayText handle$, fontSize
Print #handle$, "Place 10 ";fontSize
For i = 1 to 6
Print #handle$, "\";demoText$(i)
Next i
Print #handle$, "Flush"
End Sub
'========================================
' End Demo
'========================================
There have been some reports of corruption of graphic text lying below the window whereby scrolling down causes the newly visible text to 'blur.' This condition is easily prevented by issuing the command
#Handle, "Fill White"
prior to writing to the graphics window. A big Thank You to Giaba for identifying and sharing this fix. Also, be sure the graphics window has been flushed before attempting to print. Without a
#Handle, "Flush"
command, a blank paper may be the printed result.
The file archives included with this newsletter contains a Word Search Creator program (wordSearch.bas) that uses the new "Print VGA" and "Print SVGA" features of LB 4.01. Also included are two text files (disney.lex and LBExperts.lex) that can be loaded into the program.
Creating your own word lists is easy. Simply open your favorite text editor (your own Liberty-Made or Alyce's barebones text editor found in Liberty BASIC 4 Companion will work nicely) and follow these guidelines:
The first entry should be the Title of the Word Search
Each succeeding entry must be a word not greater than 20 characters
Each entry should contain letters only -- no spaces or punctuations
Each entry should be followed by a carriage return
Save the text file with the extension .lex (or change the code under [loadLexicon])
The current display will only accomodate 20 words. You can easily modify the code to accept more words. Keep in mind that a rather long list might cause the program to enter an endless loop as it searches in vain for a valid position for that word. The program has only limited error trapping for this kind of glitch.
Directions for both onscreen solving and hardcopy printout are accessible within the program.